package com.sdsy.quartz;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.sdsy.domain.VipWalletAddrDO;
import com.sdsy.domain.VipWalletAddrMidDO;
import com.sdsy.service.VipWalletAddrMidService;
import com.sdsy.service.VipWalletAddrService;
import com.sdsy.util.SysUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.List;

@Configuration
@EnableScheduling
@PropertySource("classpath:config/config.properties")
public class WalletAddrQuartz {

    private Logger logger = LoggerFactory.getLogger(WalletAddrQuartz.class);
    @Autowired
    private VipWalletAddrService vipWalletAddrService;
    @Autowired
    private VipWalletAddrMidService vipWalletAddrMidService;

    @Value("${switch_addr_quratz_expression}")
    private String switch_addr_quratz_expression;


    /**
     * 定时扫描地址表中是否未绑定的用户信息定时任务（暂时未用）
     */
    @Scheduled(cron = "${addr_quratz_expression}")
    public void selectWalletByStatus() {


//        if ("0".equals(switch_addr_quratz_expression)) {
//            logger.info("查询没有绑定钱包地址列表开始=================");
//            final int status = 0;
//            /** 查询没有绑定钱包地址列表 **/
//            List<VipWalletAddrDO> list = vipWalletAddrService.selectWalletByStatus();
//
//            if (!SysUtil.isNull(list)) {
//                for (int i = 0, len = list.size(); i < len; i++) {
//                    VipWalletAddrDO vo = list.get(i);
//                    if (SysUtil.isNull(vo.getWalletAddr())) {
//                        EntityWrapper<VipWalletAddrMidDO> ew = new EntityWrapper<VipWalletAddrMidDO>();
//                        ew.where("status={0}", status);
//                        List<VipWalletAddrMidDO> qb_list = vipWalletAddrMidService.selectList(ew);
//                        if (!SysUtil.isNull(qb_list) && qb_list.size() > 0) {
//                            VipWalletAddrMidDO entity = qb_list.get(0);
//                            vo.setWalletAddr(entity.getWalletAddr());
//                            vipWalletAddrService.updateById(vo);
//                            entity.setStatus(1l);
//                            vipWalletAddrMidService.updateById(entity);
//                        }
//                    }
//                }
//            } else {
//                logger.info("没有需要绑定的地址列表信息");
//            }
//        }
    }
}
